package book_management.book;

import java.util.ArrayList;
import java.util.List;

public class BookList {
    public static List<Book> books = new ArrayList<>();
    public static List<String> booksName = new ArrayList<>();

    static {
        books.add(new Book("《怎么找女朋友》" , "张三" , "教科书" ,99.99));
        books.add(new Book("《我的女朋友在哪儿》","李四","教科书" ,99.99));
        books.add(new Book("《上帝的赏赐》","王麻子","教科书" ,99.99));
        books.add(new Book("《女友是怎么找到的》","渣男王","教科书" ,999999));

        booksName.add("《怎么找女朋友》");
        booksName.add("《我的女朋友在哪儿》");
        booksName.add("《上帝的赏赐》");
        booksName.add("《女友是怎么找到的》");
    }

    public boolean contains(String booksName){
        return BookList.booksName.contains(booksName);
    }

    public void add(Book book){
        books.add(book);
        booksName.add(book.getBookName());
    }

    public void displayBooks(){
        for (Book book: books//遍历books列表里面所有元素，看到这里想不来foreach用法就再去看看，这个之前数组那块有一次你就卡了很久很久
             ) {
            System.out.println(book);
        }
    }

    public void findBook(String name){
            for (Book book:books
                 ) {
                if(book.getBookName().equals(name)){
                    System.out.println(book);
                    break;
                }
            }
        System.out.println("找啥找，找啥找，他喵的书库里就没得这本书，你搁那叭叭叭~叭叭叭");//检查，你这里一开始是循环内开辟else傻逼还为啥只能操作第一本笑死
    }

    public void removeBook(String name){
        for (Book book:books
        ) {
            if(book.getBookName().equals(name)){
                booksName.remove(name);
                books.remove(book);
                System.out.println("给你删啦");
                break;
            }
        }
        System.out.println("宝书库里没有这本书让你删哦");
    }

    public void borrowBook(String name){
        for (Book book:books
        ) {
            if(book.getBookName().equals(name)){
                if(book.isBorrowed() == false){
                    book.setBorrowed(true);
                    System.out.println("好，很有品位，这本书还在，先借给你吧");
                }else {
                    System.out.println("不好意思哈，宝儿，这本书太火了，已经借给别人了");
                }
                break;
            }
        }
        System.out.println("宝儿我们没有这本书，等我们进了货再来好吧，先看看别的吧");
    }

    public void returnBook(String name){
        for (Book book:books
        ) {
            if(book.getBookName().equals(name)){
                if(book.isBorrowed() == true){
                    book.setBorrowed(false);
                    System.out.println("好的，登记好了，欢迎常来借阅哈");
                }else {
                    System.out.println("这本书我们已经显示归还了，可能识别的书店的你记错了吧");
                }
                break;
            }
        }
        System.out.println("我们书库没有这本书这不是我们图书馆的");//在这里加一个赠与功能
    }
}
